// 用户信息、能否编辑、身份验证状态
const addressObj = () => {
	return {
		addressList: JSON.parse(localStorage.getItem('addressList')) || [],
		defaultAddressInfo: JSON.parse(localStorage.getItem('defaultAddressInfo')) || {},
		currAddressInfo: JSON.parse(localStorage.getItem('currAddressInfo')) || {},
		areaList: JSON.parse(localStorage.getItem('currAddressInfo')) || {},
	}
}
const state = addressObj()

const mutations = {
	SET_ADDRESS_LIST_INFO: (state, addressList) => {
		state.addressList = addressList
		localStorage.setItem('addressList', JSON.stringify(addressList))
	},
	SET_DEFAULT_ADDREDD_INFO: (state, defaultAddressInfo) => {
		state.defaultAddressInfo = defaultAddressInfo
		localStorage.setItem('defaultAddressInfo', JSON.stringify(defaultAddressInfo))
	},
	SET_CURR_ADDRESS_INFO: (state, currAddressInfo) => {
		state.currAddressInfo = currAddressInfo
		localStorage.setItem('currAddressInfo', JSON.stringify(currAddressInfo))
	},
	SET_AREA_LIST: (state, areaList) => {
		state.areaList = areaList
		localStorage.setItem('areaList', JSON.stringify(areaList))
	},
}

const actions = {
	//  设置所有地址
	setAddressListIUnfo({
		commit
	}, addressList) {
		commit('SET_ADDRESS_LIST_INFO', addressList)
	},
	// 设置默认地址
	setDefaultAddressInfo({
		commit
	}, defaultAddressInfo) {
		commit('SET_DEFAULT_ADDREDD_INFO', defaultAddressInfo)
	},
	//  设置当前选中的地址
	setCurrAddressInfo({
		commit
	}, currAddressInfo) {
		commit('SET_CURR_ADDRESS_INFO', currAddressInfo)
	},
	setAreaList({
		commit
	}, areaList) {
		commit('SET_AREA_LIST', areaList)
	},
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
}
